package com.app.biz.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.app.common.core.page.TableDataInfo;
import com.app.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.enums.BusinessType;
import com.app.biz.domain.BizIndustrialElectricityConsumption;
import com.app.biz.service.IBizIndustrialElectricityConsumptionService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 工业用电量临时(新)Controller
 *
 * @author SangGuangCan
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/biz/consumption/new")
public class BizIndustrialElectricityConsumptionController extends BaseController
{
    @Autowired
    private IBizIndustrialElectricityConsumptionService bizIndustrialElectricityConsumptionService;

    /**
     * 查询工业用电量临时(新)列表
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizIndustrialElectricityConsumption bizIndustrialElectricityConsumption)
    {
        startPage();
        List<BizIndustrialElectricityConsumption> list = bizIndustrialElectricityConsumptionService.selectBizIndustrialElectricityConsumptionList(bizIndustrialElectricityConsumption);
        return getDataTable(list);
    }

    /**
     * 导出工业用电量临时(新)列表
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:export')")
    @Log(title = "工业用电量临时(新)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizIndustrialElectricityConsumption bizIndustrialElectricityConsumption)
    {
        List<BizIndustrialElectricityConsumption> list = bizIndustrialElectricityConsumptionService.selectBizIndustrialElectricityConsumptionList(bizIndustrialElectricityConsumption);
        ExcelUtil<BizIndustrialElectricityConsumption> util = new ExcelUtil<BizIndustrialElectricityConsumption>(BizIndustrialElectricityConsumption.class);
        util.exportExcel(response, list, "工业用电量临时(新)数据");
    }

    /**
     * 获取工业用电量临时(新)详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizIndustrialElectricityConsumptionService.selectBizIndustrialElectricityConsumptionByBaseId(baseId));
    }

    /**
     * 新增工业用电量临时(新)
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:add')")
    @Log(title = "工业用电量临时(新)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIndustrialElectricityConsumption bizIndustrialElectricityConsumption)
    {
        return toAjax(bizIndustrialElectricityConsumptionService.insertBizIndustrialElectricityConsumption(bizIndustrialElectricityConsumption));
    }

    /**
     * 修改工业用电量临时(新)
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:edit')")
    @Log(title = "工业用电量临时(新)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIndustrialElectricityConsumption bizIndustrialElectricityConsumption)
    {
        return toAjax(bizIndustrialElectricityConsumptionService.updateBizIndustrialElectricityConsumption(bizIndustrialElectricityConsumption));
    }

    /**
     * 删除工业用电量临时(新)
     */
    @PreAuthorize("@ss.hasPermi('biz:consumption:remove')")
    @Log(title = "工业用电量临时(新)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizIndustrialElectricityConsumptionService.deleteBizIndustrialElectricityConsumptionByBaseIds(baseIds));
    }

    /**
     * 导入工业用电量数据
     * @param params
     * @param multipartFile
     * @return
     */
    @PostMapping("/importIndustrialElectricityConsumptionData")
    public AjaxResult importIndustrialElectricityConsumptionData(@RequestParam Map<String,String> params, @RequestPart("file") MultipartFile multipartFile){
        return bizIndustrialElectricityConsumptionService.importIndustrialElectricityConsumptionData(params,multipartFile);
    }

    /**
     * <p>
     *     清空所有的工业用电量数据数据
     * </p>
     * @return
     */
    @DeleteMapping("/clearAllTableData")
    public AjaxResult clearAllTableData(){
        bizIndustrialElectricityConsumptionService.clearAllTableData();
        return AjaxResult.success();
    }
    /**
     * <p>
     *     将临时表中的数据迁移到正式表虽
     * </p>
     * @return
     */
    @PostMapping("/transferDataInOneClick")
    public AjaxResult transferDataInOneClick(){
        return toAjax(bizIndustrialElectricityConsumptionService.transferDataInOneClick());
    }
}
